//
//  BroadcastData.hpp
//  Simulation
//
//  Created by Christopher Kemsley on 2/27/12.
//  Copyright (c) 2012 iAppolopolis. All rights reserved.
//

#ifndef Simulation_BroadcastData_hpp
#define Simulation_BroadcastData_hpp

#include "TransmissionBroker.hpp"

NamespaceBegin



/*
 These structure should always be used with the placement-new
 operator to put this BroadcastInformation into data within a newly
 created broadcast.
 
 For example:
 
 new (broadcast.bytes) ControlBroadcastInfo ( ControlBroadcastInfo::kSubTypeACK , 1 , 2 ) ;
 
 No deletion is necessary with other than the normal requirements for the buffer you create.
 */






struct	BroadcastInfo
{
	typedef enum {
		kTypeControl	=	1 ,
		kTypeData		=	2
	} Type ;
	
	Type const		type ;
	DeviceID const	senderAddress ;
	DeviceID const	destinationAddress ;
	
	
	BroadcastInfo	( Type inType , DeviceID inSender , DeviceID inTarget ) ;
} ;




struct	ControlBroadcastInfo : public BroadcastInfo
{
	typedef enum {
		kSubTypeACK		=	1 ,
		kSubTypeRTS		=	2 ,
		kSubTypeCTS		=	3
	} SubType ;
	
	SubType const	subType ;
	
	
	ControlBroadcastInfo		( SubType inType , DeviceID inSender , DeviceID inTarget ) ;
} ;





/*
 These functions make it easy to use the above structures
 */

void	encodeBlock		( Byte * ioBuffer , Length inMaxLength , DeviceID inSender , DeviceID inTarget ) ;
void	encodeRTS		( Byte * ioBuffer , Length inMaxLength , DeviceID inSender , DeviceID inTarget ) ;
void	encodeCTS		( Byte * ioBuffer , Length inMaxLength , DeviceID inSender , DeviceID inTarget ) ;
void	encodeACK		( Byte * ioBuffer , Length inMaxLength , DeviceID inSender , DeviceID inTarget ) ;

void	decodeBroadcast	( Byte const * inBuffer , BroadcastInfo::Type & outType , DeviceID & outSender , DeviceID & outTarget ) ;
void	decodeControl	( Byte const * inBuffer , ControlBroadcastInfo::SubType & outType ) ; // if type is kTypeControl







NamespaceEnd

#endif
